/*
 * First Lastname, ID ********, Assignment 3
 * File: array_list.c
 */

#include "array_list.h"

#/* array list initialization - contains what is typically in a constructor */
#void al_init(Partlist *l)
#{
#   l->last = 10;
#}

/* return first position of array list */
int al_first(Partlist *l)
{
   return 0;
}

/* return "one past the end" position of array list */
int al_end(Partlist *l)
{
   return l->last + 1;
}

#/* returns position one after the current position of array list */
#int al_next(int current_pos, Partlist *l)
#{
#   return current_pos + 1;
#}

int al_is_full(Partlist *l)
{
   return (l->last == MAX_PARTS - 1);
}

/* return element at position of array list */
Part al_retrieve(int position, Partlist *l)
{
   return l->elements[position];
}

/* delete element at position of array list */
void al_delete(int pos, Partlist *l)
{
   int i;
   if (pos > l->last || pos < 0) return;
   for (i = pos; i < l->last; i++)
   {
      l->elements[i] = l->elements[i+1];
   }
   l->last--;
}

/* add element to array list */
void al_add(Part newpart, Partlist *l)
{
   l->last++;
   l->elements[l->last] = newpart;
}

